package nxu.it.interceptor;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * @author yangliu
 * @project jfinal-app-1
 * @sid 12020243892
 * @date 2022/11/7 - 8:54
 */
public class LoginFormValidator extends Validator {
    String errorKey = "errorMessage";

    @Override
    protected void validate(Controller controller) {
        String username = controller.get("username");
        String password = controller.get("password");
        this.setShortCircuit(true);
        validateRequiredString("username",errorKey,"用户名为空白");
        validateRequiredString("password",errorKey,"密码为空白");
        System.out.println("这里还ok");
//        if (username == null) {
//            addError(errorKey, "账户不正确");
//            return;
//        }
//        if (password == null) {
//            addError(errorKey, "密码不正确");
//            return;
//        }
    }

    @Override
    protected void handleError(Controller controller) {
        controller.set("success","false");
        controller.renderJson();
    }
}
